class Solution {
public:
    int maxRotateFunction(vector<int> &A)
    {
        int f = 0;
        int sum = 0;
        for(int i = 0;i < A.size();++i) {
            sum += A[i];
            f += i * A[i];
        }
        int maxV = f;
        for(int j = 0;j < A.size();++j) {
            int index = (A.size() - j - 1);
            f = f - A[index] * (A.size() - 1) + (sum - A[index]);
            maxV = max(maxV, f);
        }
        return maxV;
    }
};